package com.shuqi.model.parse.parser;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import android.text.TextUtils;

import com.shuqi.model.bean.VerifyBookDownUrlInfo;
import com.shuqi.model.parse.HandlerBase;

/**
 * 验证书籍下载地址
 */
public class VerifyBookDownUrlPaser extends HandlerBase {

    private VerifyBookDownUrlInfo info;

    @Override
    public Object getParsedData() {
        return info;
    }

    @Override
    public void startDocument() throws SAXException {
        info = new VerifyBookDownUrlInfo();
        super.startDocument();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {
        if ("serverInfo".equals(localName)) {
            info.setCode(Integer.valueOf(attributes.getValue("state")));
            info.setMessage(attributes.getValue("message"));
        } else if ("bagInfo".equals(localName)) {
            if(info!=null && 200 == info.getCode()){
                info.setCode(Integer.valueOf(attributes.getValue("state")));
                info.setMessage(attributes.getValue("message"));
                if(200 == info.getCode()){
                    info.setDownLoadUrl(attributes.getValue("cdnUrl"));
                    if(!TextUtils.isEmpty(attributes.getValue("threadCount"))){
                        info.setThreadCount(Integer.valueOf(attributes.getValue("threadCount")));
                    }
                }
            }
        }
    }

  
}
